﻿// * Write a program that converts a number in the range [0...999] to a text corresponding to its English pronunciation. 
// Examples:
//	0 -> "Zero"
//	273 -> "Two hundred seventy three"
//	400 -> "Four hundred"
//	501 -> "Five hundred and one"
//	711 -> "Seven hundred and eleven"

using System;

class ConvertNumberToText
{
    static void Main()
    {
        Console.Write("Please, enter number between 0 and 999 : ");
        string str = Console.ReadLine();
        int number = 0;
        while (!int.TryParse(str, out number))
        {
            Console.Write("Invalid input. Please, re-enter your number between 0 and 999 : ");
            str = Console.ReadLine();
        }

        string zero = "zero";
        string one = "one";
        string two = "two";
        string three = "three";
        string four = "four";
        string five = "five";
        string six = "six";
        string seven = "seven";
        string eight = "eight";
        string nine = "nine";
        string ten = "ten";
        string eleven = "eleven";
        string twelve = "twelve";
        string thirteen = "thirteen";
        string fourteen = "fourteen";
        string fifteen = "fifteen";
        string sixteen = "sixteen";
        string seventeen = "seventeen";
        string eighteen = "eighteen";
        string nineteen = "nineteen";
        string twenty = "twenty";
        string thirty = "thirty";
        string fourty = "fourty";
        string fifty = "fifty";
        string sixty = "sixty";
        string seventy = "seventy";
        string eighty = "eighty";
        string ninety = "ninety";
        string hundred = "hundred";

        string newNumber = "";
        int units = 0;
        int tens = 0;
        int hundreds = 0;
        string unitsStr = "";
        string tensStr = "";
        string hundredsStr = "";

        if (number >= 0 && number <= 9)
        {
            switch (number)
            {
                case 0: newNumber = zero; break;
                case 1: newNumber = one; break;
                case 2: newNumber = two; break;
                case 3: newNumber = three; break;
                case 4: newNumber = four; break;
                case 5: newNumber = five; break;
                case 6: newNumber = six; break;
                case 7: newNumber = seven; break;
                case 8: newNumber = eight; break;
                case 9: newNumber = nine; break;
                default: Console.WriteLine("Something went wrong."); break;
            }

        }
        else if (number >= 10 && number <= 19)
        {
            switch (number)
            {
                case 10: newNumber = ten; break;
                case 11: newNumber = eleven; break;
                case 12: newNumber = twelve; break;
                case 13: newNumber = thirteen; break;
                case 14: newNumber = fourteen; break;
                case 15: newNumber = fifteen; break;
                case 16: newNumber = sixteen; break;
                case 17: newNumber = seventeen; break;
                case 18: newNumber = eighteen; break;
                case 19: newNumber = nineteen; break;
                default: Console.WriteLine("Something went wrong."); break;
            }

        }
        else if (number >= 20 && number <= 99)
        {
            units = number % 10;
            number = number / 10;
            tens = number % 10;

            switch (tens)
            {
                case 2: tensStr = twenty; break;
                case 3: tensStr = thirty; break;
                case 4: tensStr = fourty; break;
                case 5: tensStr = fifty; break;
                case 6: tensStr = sixty; break;
                case 7: tensStr = seventy; break;
                case 8: tensStr = eighty; break;
                case 9: tensStr = ninety; break;
                default: Console.WriteLine("Something went wrong."); break;
            }
            switch (units)
            {
                case 0: unitsStr = zero; break;
                case 1: unitsStr = one; break;
                case 2: unitsStr = two; break;
                case 3: unitsStr = three; break;
                case 4: unitsStr = four; break;
                case 5: unitsStr = five; break;
                case 6: unitsStr = six; break;
                case 7: unitsStr = seven; break;
                case 8: unitsStr = eight; break;
                case 9: unitsStr = nine; break;
                default: Console.WriteLine("Something went wrong."); break;
            }

            if (units == 0)
            {
                newNumber = tensStr;
            }
            else
            {
                newNumber = tensStr + " " + unitsStr;
            }

        }
        else if (number >= 100 && number <= 999)
        {
            units = number % 10;
            number = number / 10;
            tens = number % 10;
            number = number / 10;
            hundreds = number % 10;

            switch (hundreds)
            {
                case 1: hundredsStr = one + " " + hundred; break;
                case 2: hundredsStr = two + " " + hundred; break;
                case 3: hundredsStr = three + " " + hundred; break;
                case 4: hundredsStr = four + " " + hundred; break;
                case 5: hundredsStr = five + " " + hundred; break;
                case 6: hundredsStr = six + " " + hundred; break;
                case 7: hundredsStr = seven + " " + hundred; break;
                case 8: hundredsStr = eight + " " + hundred; break;
                case 9: hundredsStr = nine + " " + hundred; break;
                default: Console.WriteLine("Something went wrong."); break;
            }

            if (units == 0 && tens == 0)
            {
                newNumber = hundredsStr;
            }
            else if (tens == 0)
            {
                switch (units)
                {
                    case 1: unitsStr = one; break;
                    case 2: unitsStr = two; break;
                    case 3: unitsStr = three; break;
                    case 4: unitsStr = four; break;
                    case 5: unitsStr = five; break;
                    case 6: unitsStr = six; break;
                    case 7: unitsStr = seven; break;
                    case 8: unitsStr = eight; break;
                    case 9: unitsStr = nine; break;
                    default: Console.WriteLine("Something went wrong."); break;
                }

                newNumber = hundredsStr + " and " + unitsStr;
            }
            else if (tens == 1)
            {
                switch (units)
                {
                    case 0: tensStr = ten; break;
                    case 1: tensStr = eleven; break;
                    case 2: tensStr = twelve; break;
                    case 3: tensStr = thirteen; break;
                    case 4: tensStr = fourteen; break;
                    case 5: tensStr = fifteen; break;
                    case 6: tensStr = sixteen; break;
                    case 7: tensStr = seventeen; break;
                    case 8: tensStr = eighteen; break;
                    case 9: tensStr = nineteen; break;
                    default: Console.WriteLine("Something went wrong."); break;
                }
                newNumber = hundredsStr + " and " + tensStr;
            }
            else
            {
                switch (tens)
                {
                    case 2: tensStr = twenty; break;
                    case 3: tensStr = thirty; break;
                    case 4: tensStr = fourty; break;
                    case 5: tensStr = fifty; break;
                    case 6: tensStr = sixty; break;
                    case 7: tensStr = seventy; break;
                    case 8: tensStr = eighty; break;
                    case 9: tensStr = ninety; break;
                    default: Console.WriteLine("Something went wrong."); break;
                }
                switch (units)
                {
                    case 0: unitsStr = zero; break;
                    case 1: unitsStr = one; break;
                    case 2: unitsStr = two; break;
                    case 3: unitsStr = three; break;
                    case 4: unitsStr = four; break;
                    case 5: unitsStr = five; break;
                    case 6: unitsStr = six; break;
                    case 7: unitsStr = seven; break;
                    case 8: unitsStr = eight; break;
                    case 9: unitsStr = nine; break;
                    default: Console.WriteLine("Something went wrong."); break;
                }

                if (units == 0)
                {
                    newNumber = hundredsStr + " and " + tensStr;
                }
                else
                {
                    newNumber = hundredsStr + " " + tensStr + " " + unitsStr;
                }
            }
        }

        string result = newNumber.Substring(0, 1).ToUpper() + newNumber.Substring(1).ToLower();
        Console.WriteLine("Your number is : " + result);
    }
}
